import { Rule, RuleType } from '@midwayjs/validate';
import { ApiProperty } from '@midwayjs/swagger';
import { R } from '../../../common/base.error.util';
import {
  stringRequired,
  phone,
  email,
} from '../../../common/common.validate.rules';
import { UserEntity } from '../entity/user';
import { BaseDTO } from '../../../common/base.dto';

export class UserDTO extends BaseDTO<UserEntity> {
  @ApiProperty({ description: '用户名称' })
  @Rule(stringRequired.error(R.validateError('用户名称不能为空')))
  userName: string;

  @ApiProperty({ description: '用户昵称' })
  @Rule(stringRequired.error(R.validateError('用户昵称不能为空')))
  nickName: string;

  @ApiProperty({ description: '手机号' })
  @Rule(phone.error(R.validateError('无效的手机号格式')))
  phoneNumber: string;

  @ApiProperty({ description: '邮箱' })
  @Rule(email.error(R.validateError('无效的邮箱格式')))
  email: string;

  @ApiProperty({ description: '密码' })
  password?: string;

  // @ApiProperty({ description: '性别（0:女，1:男）', nullable: true })
  @ApiProperty({
    description: '性别（0:女，1:男）',
    nullable: true,
  })
  @Rule(
    RuleType.number()
      .valid(0, 1)
      .allow(null)
      .error(R.validateError('性别只能为0或1'))
  )
  sex?: number;
}
